<extend name="Public/base" />

<block name="style">
    <link href="__STATIC__/iCheck/skins/flat/green.css" rel="stylesheet">
</block>
<block name="body">

    <div class="right_col" role="main">
        <div class="">



            <div class="page-title">
                <div class="title_left">
                    <h3>{$meta_title} <small>Some examples to get you started</small></h3>
                </div>

                <div class="title_right">
<!--                    <div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="Search for...">
                            <span class="input-group-btn">
                                <button class="btn btn-default" type="button">Go!</button>
                            </span>
                        </div>
                    </div>-->
                </div>
            </div>

            <div class="clearfix"></div>
           




            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>创建菜单 <small>Create menu</small></h2>

                        <ul class="nav navbar-right panel_toolbox">
                            <li class="">
                                <a href="javascript:;"> <button  id="export" class="btn btn-success">&nbsp;立即备份</button></a>
                            </li>
                            <li class="">
                                <a href="{:U('Database/optimize')}" class='post_common_url'><button type="button" class="btn btn-danger"><i class="fa fa-trash-o"></i>&nbsp;优化表</button></a>
                            </li>
                            <li class="">
                                <a href="{:U('Database/repair')}" class='post_common_url'><button type="button" class="btn btn-danger"><i class="fa fa-trash-o"></i>&nbsp;修复表</button></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>


                    <div class="x_content">

  <form id="export-form" method="post" action="{:U('export')}">
                        <div class="table-responsive">
                            <table class="table table-striped jambo_table bulk_action">
                                <thead>
                                    <tr class="headings">
                                        <th>
                                           <input class="check-all" checked="chedked" type="checkbox" value="">
                                        </th>
                                        <th class="column-title">表名 </th>
                                        <th class="column-title">数据量 </th>
                                        <th class="column-title">数据大小 </th>
                                        <th class="column-title">创建时间 </th>
                                        
                                        <th class="column-title">备份状态 </th>
                                      
                                        <th class="column-title no-link last"><span class="nobr">操作</span>
                                        </th>
                                        <th class="bulk-actions" colspan="6">
                                            <a class="antoo" style="color:#fff; font-weight:500;">Bulk Actions ( <span class="action-cnt"> </span> ) <i class="fa fa-chevron-down"></i></a>
                                        </th>
                                    </tr>
                                </thead>

                                <tbody>

                                <notempty name="list">
    <volist name='list' id='table'> 
                                    <tr class="even pointer  del_id_{$table.name}">
                                        <td class="a-center ">
                                             <input class="ids" checked="chedked" type="checkbox" name="tables[]" value="{$table.name}">
                             </td>
                                         <td>{$table.name}</td>
                            <td>{$table.rows}</td>
                            <td>{$table.data_length|format_bytes}</td>
                            <td>{$table.create_time}</td>
                            <td class="info">未备份</td>
                            
                                        <td>
                                            <a href="{:U('Database/optimize',array('tables'=>$table['name']))}" class="btn btn-info btn-xs get_common_href"><i class="fa fa-pencil"></i>优化表</a>
                                           <a href="{:U('Database/repair',array('tables'=>$table['name']))}" class="btn btn-danger btn-xs  get_common_href"><i class="fa fa-trash-o"></i>修复表</a>
                                        </td>
                                    </tr>
    </volist>
                                    <else /> 
                                <tr class="even pointer  del_id_{$vo.id}">
                                <td  colspan="9">
                                    无相关记录
                                     </td>
                                        </tr>
                                </notempty>
                                </tbody>
                            </table>
                        </div>
        </form>


                                 
                    </div>    
                </div>   
            </div>
            
            
            
            
            
            
            
        </div>
    </div>
</div>
</block>
<block name="script">
 <script type="text/javascript">
    (function($){
        
        $(".check-all").click(function(){
		$(".ids").prop("checked", this.checked);
	});
        var that=this;
        var $form = $("#export-form"), $export = $("#export"), tables
            $optimize = $("#optimize"), $repair = $("#repair");

        $optimize.add($repair).click(function(){
            $.post(this.href, $form.serialize(), function(data){
                if(data.status){
                    updateAlert(data.info,'alert-success');
                } else {
                    updateAlert(data.info,'alert-error');
                }
                setTimeout(function(){
	                $('#top-alert').find('button').click();
	                $(that).removeClass('disabled').prop('disabled',false);
	            },1500);
            }, "json");
            return false;
        });

        $export.click(function(){
            $export.parent().children().addClass("disabled");
            $export.html("正在发送备份请求...");
            $.post(
                $form.attr("action"),
                $form.serialize(),
                function(data){
                    if(data.code){
                        tables = data.tables;
                        $export.html(data.msg + "开始备份，请不要关闭本页面！");
                        backup(data.tab);
                        window.onbeforeunload = function(){ return "正在备份数据库，请不要关闭！" }
                    } else {
                        ui.error(data.msg);
                        $export.parent().children().removeClass("disabled");
                        $export.html("立即备份");
                        setTimeout(function(){
        	                $('#top-alert').find('button').click();
        	                $(that).removeClass('disabled').prop('disabled',false);
        	            },1500);
                    }
                },
                "json"
            );
            return false;
        });

        function backup(tab, status){
            status && showmsg(tab.id, "开始备份...(0%)");
          
            $.get($form.attr("action"), tab, function(data){
                if(data.code){
                    showmsg(tab.id, data.msg);

                    if(!$.isPlainObject(data.tab)){
                        $export.parent().children().removeClass("disabled");
                        $export.html("备份完成，点击重新备份");
                        window.onbeforeunload = function(){ return null }
                        return;
                    }
                    backup(data.tab, tab.id != data.tab.id);
                } else {
                    ui.error(data.msg);
                    $export.parent().children().removeClass("disabled");
                    $export.html("立即备份");
                    setTimeout(function(){
    	                $('#top-alert').find('button').click();
    	                $(that).removeClass('disabled').prop('disabled',false);
    	            },1500);
                }
            }, "json");

        }

        function showmsg(id, msg){
            $form.find("input[value=" + tables[id] + "]").closest("tr").find(".info").html(msg);
        }
    })(jQuery);
    </script>
    <script src="__STATIC__/iCheck/icheck.min.js"></script>
    <script>
        Lzy.highlight_subnav('{:U('index?type=export')}');
    </script>
</block>
